
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/physics/mechanics/examples/rollingdisc_example_lagrange.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:29:31 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>A rolling disc using Lagrange’s Method &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../../../" id="documentation_options" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../../../live.sympy.org/static/live-sphinx.js"></script>
    
    <link rel="shortcut icon" href="../../../../_static/sympy-notailtext-favicon.ico"/>
    <link href="rollingdisc_example_lagrange.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
    <link rel="next" title="A bicycle" href="bicycle_example.html" />
    <link rel="prev" title="A rolling disc, with Kane’s method and constraint forces" href="rollingdisc_example_kane_constraints.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="bicycle_example.html" title="A bicycle"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="rollingdisc_example_kane_constraints.html" title="A rolling disc, with Kane’s method and constraint forces"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="../index.html" >Classical Mechanics</a> &#187;</li>
          <li class="nav-item nav-item-4"><a href="../examples.html" >Examples for Physics/Mechanics</a> &#187;</li>
          <li class="nav-item nav-item-5"><a href="rollingdisc_example.html" accesskey="U">A rolling disc</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">A rolling disc using Lagrange’s Method</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="a-rolling-disc-using-lagrange-s-method">
<h1>A rolling disc using Lagrange’s Method<a class="headerlink" href="#a-rolling-disc-using-lagrange-s-method" title="Permalink to this headline">¶</a></h1>
<p>Here the rolling disc is formed from the contact point up, removing the
need to introduce generalized speeds. Only 3 configuration and 3
speed variables are needed to describe this system, along with the
disc’s mass and radius, and the local gravity.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.mechanics</span> <span class="kn">import</span> <span class="o">*</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mechanics_printing</span><span class="p">(</span><span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q1</span><span class="p">,</span> <span class="n">q2</span><span class="p">,</span> <span class="n">q3</span> <span class="o">=</span> <span class="n">dynamicsymbols</span><span class="p">(</span><span class="s1">&#39;q1 q2 q3&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q1d</span><span class="p">,</span> <span class="n">q2d</span><span class="p">,</span> <span class="n">q3d</span> <span class="o">=</span> <span class="n">dynamicsymbols</span><span class="p">(</span><span class="s1">&#39;q1 q2 q3&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">g</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;r m g&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The kinematics are formed by a series of simple rotations. Each simple
rotation creates a new frame, and the next rotation is defined by the new
frame’s basis vectors. This example uses a 3-1-2 series of rotations, or
Z, X, Y series of rotations. Angular velocity for this is defined using
the second frame’s basis (the lean frame).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">ReferenceFrame</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">orientnew</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="s1">&#39;Axis&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">q1</span><span class="p">,</span> <span class="n">N</span><span class="o">.</span><span class="n">z</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span> <span class="o">=</span> <span class="n">Y</span><span class="o">.</span><span class="n">orientnew</span><span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="s1">&#39;Axis&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">q2</span><span class="p">,</span> <span class="n">Y</span><span class="o">.</span><span class="n">x</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">L</span><span class="o">.</span><span class="n">orientnew</span><span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="s1">&#39;Axis&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">q3</span><span class="p">,</span> <span class="n">L</span><span class="o">.</span><span class="n">y</span><span class="p">])</span>
</pre></div>
</div>
<p>This is the translational kinematics. We create a point with no velocity
in N; this is the contact point between the disc and ground. Next we form
the position vector from the contact point to the disc’s center of mass.
Finally we form the velocity and acceleration of the disc.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Point</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">set_vel</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dmc</span> <span class="o">=</span> <span class="n">C</span><span class="o">.</span><span class="n">locatenew</span><span class="p">(</span><span class="s1">&#39;Dmc&#39;</span><span class="p">,</span> <span class="n">r</span> <span class="o">*</span> <span class="n">L</span><span class="o">.</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dmc</span><span class="o">.</span><span class="n">v2pt_theory</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">R</span><span class="p">)</span>
<span class="go">r*(sin(q2)*q1&#39; + q3&#39;)*L.x - r*q2&#39;*L.y</span>
</pre></div>
</div>
<p>Forming the inertia dyadic.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">=</span> <span class="n">inertia</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="n">m</span> <span class="o">/</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">r</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">m</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">r</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">m</span> <span class="o">/</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">r</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mprint</span><span class="p">(</span><span class="n">I</span><span class="p">)</span>
<span class="go">m*r**2/4*(L.x|L.x) + m*r**2/2*(L.y|L.y) + m*r**2/4*(L.z|L.z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">BodyD</span> <span class="o">=</span> <span class="n">RigidBody</span><span class="p">(</span><span class="s1">&#39;BodyD&#39;</span><span class="p">,</span> <span class="n">Dmc</span><span class="p">,</span> <span class="n">R</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">I</span><span class="p">,</span> <span class="n">Dmc</span><span class="p">))</span>
</pre></div>
</div>
<p>We then set the potential energy and determine the Lagrangian of the rolling
disc.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">BodyD</span><span class="o">.</span><span class="n">potential_energy</span> <span class="o">=</span> <span class="o">-</span> <span class="n">m</span> <span class="o">*</span> <span class="n">g</span> <span class="o">*</span> <span class="n">r</span> <span class="o">*</span> <span class="n">cos</span><span class="p">(</span><span class="n">q2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lag</span> <span class="o">=</span> <span class="n">Lagrangian</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">BodyD</span><span class="p">)</span>
</pre></div>
</div>
<p>Then the equations of motion are generated by initializing the
<code class="docutils literal notranslate"><span class="pre">LagrangesMethod</span></code> object. Finally we solve for the generalized
accelerations(q double dots) with the <code class="docutils literal notranslate"><span class="pre">rhs</span></code> method.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="p">[</span><span class="n">q1</span><span class="p">,</span> <span class="n">q2</span><span class="p">,</span> <span class="n">q3</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span> <span class="o">=</span> <span class="n">LagrangesMethod</span><span class="p">(</span><span class="n">Lag</span><span class="p">,</span> <span class="n">q</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">le</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">form_lagranges_equations</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">le</span><span class="o">.</span><span class="n">simplify</span><span class="p">();</span> <span class="n">le</span>
<span class="go">Matrix([</span>
<span class="go">[m*r**2*(6*sin(q2)*q3&#39;&#39; + 5*sin(2*q2)*q1&#39;*q2&#39; + 6*cos(q2)*q2&#39;*q3&#39; - 5*cos(2*q2)*q1&#39;&#39;/2 + 7*q1&#39;&#39;/2)/4],</span>
<span class="go">[                      m*r*(4*g*sin(q2) - 5*r*sin(2*q2)*q1&#39;**2/2 - 6*r*cos(q2)*q1&#39;*q3&#39; + 5*r*q2&#39;&#39;)/4],</span>
<span class="go">[                                                 3*m*r**2*(sin(q2)*q1&#39;&#39; + cos(q2)*q1&#39;*q2&#39; + q3&#39;&#39;)/2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lrhs</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">rhs</span><span class="p">();</span> <span class="n">lrhs</span><span class="o">.</span><span class="n">simplify</span><span class="p">();</span> <span class="n">lrhs</span>
<span class="go">Matrix([</span>
<span class="go">[                                                          q1&#39;],</span>
<span class="go">[                                                          q2&#39;],</span>
<span class="go">[                                                          q3&#39;],</span>
<span class="go">[                       -2*(2*tan(q2)*q1&#39; + 3*q3&#39;/cos(q2))*q2&#39;],</span>
<span class="go">[-4*g*sin(q2)/(5*r) + sin(2*q2)*q1&#39;**2/2 + 6*cos(q2)*q1&#39;*q3&#39;/5],</span>
<span class="go">[         (-5*cos(q2)*q1&#39; + 6*tan(q2)*q3&#39; + 4*q1&#39;/cos(q2))*q2&#39;]])</span>
</pre></div>
</div>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../../index.html">
              <img class="logo" src="../../../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="rollingdisc_example_kane_constraints.html"
                        title="previous chapter">A rolling disc, with Kane’s method and constraint forces</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="bicycle_example.html"
                        title="next chapter">A bicycle</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../../_sources/modules/physics/mechanics/examples/rollingdisc_example_lagrange.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="bicycle_example.html" title="A bicycle"
             >next</a> |</li>
        <li class="right" >
          <a href="rollingdisc_example_kane_constraints.html" title="A rolling disc, with Kane’s method and constraint forces"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="../index.html" >Classical Mechanics</a> &#187;</li>
          <li class="nav-item nav-item-4"><a href="../examples.html" >Examples for Physics/Mechanics</a> &#187;</li>
          <li class="nav-item nav-item-5"><a href="rollingdisc_example.html" >A rolling disc</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">A rolling disc using Lagrange’s Method</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/physics/mechanics/examples/rollingdisc_example_lagrange.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:29:32 GMT -->
</html>